﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace Lada.Windows.Data
{
  public class EnumToBooleanConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (value == null || parameter == null)
        return DependencyProperty.UnsetValue;

      string checkValue = value.ToString();
      string targetValue = parameter.ToString();
      return checkValue.Equals(targetValue, StringComparison.InvariantCultureIgnoreCase);
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (value == null || parameter == null)
        return DependencyProperty.UnsetValue;

      bool useValue = (bool)value;
      string targetValue = parameter.ToString();
      if (useValue)
        return Enum.Parse(targetType, targetValue);

      return DependencyProperty.UnsetValue;
    }
  }
}
